package com.atguigu.spzx.user.controller;

import com.atguigu.spzx.model.pojo.user.Region;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.user.service.RegionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/user/region")
@Tag(name="地区管理")
public class RegionController {

    @Autowired
    private RegionService regionService;

    @GetMapping("/getRegionByCode/{code}")
    @Operation(summary = "获取地区信息")
    public Result<Region> getRegionByCode(@PathVariable("code")String code){
        return Result.ok(regionService.getOne(new QueryWrapper<Region>().eq("code",code)));
    }

    @GetMapping("/findByParentCode/{parentCode}")
    @Operation(summary = "根据parentId获取地区信息")
    public Result<List<Region>> getByParentId(@PathVariable("parentCode")String parentCode){
        return Result.ok(regionService.list(new QueryWrapper<Region>().eq("parent_code",parentCode)));
    }


}
